﻿@{
    ViewBag.Title = "AddProduct";
    Layout = "~/Areas/AdminInfo/Views/Shared/_LayoutPage1.cshtml";
}

@model Gtkj.CMS.Model.ProductInfo
<style>
    .layui-form-pane .layui-form-label {
        width: 100px;
    }
</style>
<script src="~/Scripts/utf8-net/ueditor.config.js"></script>
<script src="~/Scripts/utf8-net/ueditor.all.min.js"></script>
<script src="~/Scripts/utf8-net/lang/zh-cn/zh-cn.js"></script>
<div class="container-fluid larry-wrapper">
    <div class="row">
        <div class="col-xs-12 col-sm-12 col-md-12">
            <section class="panel panel-padding">

                <form id="form1" class="layui-form layui-form-pane" data-render="true">
                    <div class="layui-form-item">
                        <label class="layui-form-label">标题</label>
                        <div class="layui-input-block">
                            <input type="text" name="Title" value="@(Model==null?"": Model.Title)" placeholder="请输入标题" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">藏主</label>
                        <div class="layui-input-block">
                            <input type="text" name="CollectionName" value="@(Model==null?"": Model.CollectionName)" placeholder="请输入藏主" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">地址</label>
                        <div class="layui-input-block">
                            <input type="text" name="Address" value="@(Model==null?"": Model.Address)" placeholder="请输入地址" class="layui-input ">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">QQ</label>
                        <div class="layui-input-block">
                            <input type="text" name="CollectionQQ" value="@(Model==null?"": Model.CollectionQQ)" placeholder="请输入QQ" class="layui-input ">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">交易类型</label>
                        <div class="layui-input-block">
                            <select name="TradingType" id="TradingType" lay-filter="TradingType">
                                <option value="all" selected="">-- 请选择 --</option>
                                @{
                                    if (ViewBag.TradingType != null)
                                    {
                                        foreach (Gtkj.CMS.Model.Models.SelectViewModels item in ViewBag.TradingType)
                                        {
                                            <option value="@item.Value">@item.Text</option>
                                        }
                                    }

                                }
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">金额</label>
                        <div class="layui-input-block">
                            <input type="text" name="Money" value="@(Model==null?0 :Model.Money)" onkeydown=" if (!(event.keyCode == 46) && !(event.keyCode == 8) && !(event.keyCode == 37) && !(event.keyCode == 39))
     if (!((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105)))
         event.returnValue = false;" placeholder="请输入金额" class="layui-input ">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">父级分类</label>
                        <div class="layui-input-block">
                            <select name="ProductTypeID" id="ProductTypeID" lay-filter="ProductTypeID">
                                <option value="all" selected="">-- 请选择 --</option>
                                @{
                                    if (ViewBag.ProductType != null)
                                    {
                                        foreach (Gtkj.CMS.Model.ProductType item in ViewBag.ProductType)
                                        {
                                            <option value="@item.TypeID">@item.Name</option>
                                        }
                                    }

                                }
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">子级分类</label>
                        <div class="layui-input-block">
                            <select name="ChchildProductTypeID" id="ChchildProductTypeID" lay-filter="ChchildProductTypeID">
                                <option value="all" selected="">-- 请选择 --</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">规格</label>
                        <div class="layui-input-block">
                            <input type="text" name="Specifications" value="@(Model==null?"": Model.Specifications)" placeholder="请输入规格" class="layui-input ">
                        </div>
                    </div>

                    <div class="layui-form-item ">
                        <label class="layui-form-label">收藏时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="CollectionTime" class="layui-input" onclick="layui.laydate({elem: this, istime: true, format: 'YYYY-MM-DD hh:mm:ss'})" value="@(Model == null ? "" : Model.CollectionTime.ToString())" placeholder="请输入收藏时间">
                        </div>
                    </div>
                    <div class="layui-form-item ">
                        <label class="layui-form-label">阅读量</label>
                        <div class="layui-input-block">
                            <input type="text" onkeydown=" if (!(event.keyCode == 46) && !(event.keyCode == 8) && !(event.keyCode == 37) && !(event.keyCode == 39))
     if (!((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105)))
         event.returnValue = false;" name="BrowseCount" value="@(Model == null ? 0 : Model.BrowseCount == null ? 0 : Model.BrowseCount)" placeholder="请输入阅读量" class="layui-input ">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">首页分类置顶</label>
                        <div class="layui-input-block">
                            <select name="IsTop" id="IsTop" lay-filter="IsTop">
                                <option value="">请选择</option>
                                <option value="1">是</option>
                                <option value="0">否</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">首页藏品会员展示区</label>
                        <div class="layui-input-block">
                            <select name="IsShowCollection" id="IsShowCollection" lay-filter="IsShowCollection">
                                <option value="">请选择</option>
                                <option value="1">是</option>
                                <option value="0">否</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">首页加急区</label>
                        <div class="layui-input-block">
                            <select name="Isurgent" id="Isurgent" lay-filter="Isurgent">
                                <option value="">请选择</option>
                                <option value="1">是</option>
                                <option value="0">否</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否成交</label>
                        <div class="layui-input-block">
                            <select name="IsClinch" id="IsClinch" lay-filter="IsClinch">
                                <option value="">请选择</option>
                                <option value="1">是</option>
                                <option value="0">否</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">上传主图片</label>
                        <div class="layui-input-block">
                            <input type="file" lay-type="images" name="Logo" class="layui-upload-file">默认第一张为主图
                            <input type="hidden" name="Image" id="imgsrc">
                            <p id="img-error" class="error">
                                @{
                                    if (Model != null)
                                    {
                                        if (Model.Image != null || Model.Image != "")
                                        {
                                            
                                            <a href="javascript:void(0)">
                                                X<img src="@Model.Image" alt="..." class="img-thumbnail" height="150" width="150">
                                            </a>
                                            if (ViewBag.ImageList != null)
                                            {
                                                foreach (Gtkj.CMS.Model.ProductImages item in ViewBag.ImageList)
                                                {
                                                    <a href="javascript:void(0)">X<img src="@item.ImageURL" alt="..." class="img-thumbnail" height="150" width="150"></a>
                                                }

                                            }
                                        }
                                    }
}
                            </p>
                        </div>
                    </div>

                    <div class="layui-form-item ">
                        <label class="layui-form-label">内容</label>
                        <div class="layui-input-block">
                            <script id="editor" type="text/plain" style="width:100%;height:500px;">
                                @(Model == null ? null : Html.Raw(Model.Contenst))
                            </script>
                            @*<textarea class="layui-textarea layui-hide" name="Contenst" lay-verify="content" id="LAY_demo_editor">@(Model == null ? null : Html.Raw(Model.Contenst))</textarea>*@
                            @*<textarea name="content" id="conntent" style="display:none;">@(Model == null ? "": Model.Contentxt)</textarea>*@
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit="" lay-filter="sub">立即提交</button>
                            @if (Model == null)
                            {
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            }
                        </div>
                    </div>
                    <input type="hidden" name="ID" value="@(Model==null?"":Model.ProductID.ToString())" />
                </form>
            </section>
        </div>
    </div>
</div>
<script>
    var $;
    //var $Type = $("Type");
    layui.use(['form', 'upload', 'layedit', 'jqform', 'laydate'], function () {
        var editIndex;
        $ = layui.jquery,
            jqform=layui.jqform,
         form = layui.form(), layedit = layui.layedit, laydate = layui.laydate;


        UE.getEditor('editor');

        $("#TradingType").val(@(Model == null ? "" : Model.TradingType.ToString()));
        $("#IsTop").val(@(Model == null ? "" : Model.IsTop?"1":"0"));
        $("#IsShowCollection").val(@(Model == null ? "" : Model.IsShowCollection?"1":"0"));
        $("#Isurgent").val(@(Model == null ? "" : (bool)Model.Isurgent ? "1" : "0"));
        $('#ProductTypeID').val(@(Model == null ? "" : Model.ParentID.ToString()));
        $('#IsClinch').val(@(Model == null ? "" : Model.IsClinch?"1":"0".ToString()));
        form.render(); //这个很重要
        var ID=@(Model==null?0:Model.ParentID);
        if (ID!=0) {
            $.getJSON("/AdminInfo/AdminProduct/ProductTypeChchild?TypeID=" + $('#ProductTypeID').val(), function (data) {
                var optionstring = "";
                $.each(data.data, function (i, item) {
                    optionstring += "<option value=\"" + item.TypeID + "\" >" + item.Name + "</option>";
                });
                $("#ChchildProductTypeID").html(optionstring);

                $('#ChchildProductTypeID').val(@(Model == null ? "" : Model.ChildID.ToString()));
                form.render(); //这个很重要
            });

        }
        layui.upload({
            url: '/Upload/UploadPic' //上传接口file1
         , success: function (res) { //上传成功后的回调
             //console.log(res);
             //$('#imgsrc').val(res.data);
             $('#img-error').append('<a href="javascript:void(0)">X<img src="'+res.data+'" alt="..." class="img-thumbnail" height="150" width="150"></a>');
         }
        });
        form.on('select(ProductTypeID)', function (data) {
            $.getJSON("/AdminInfo/AdminProduct/ProductTypeChchild?TypeID=" + data.value, function (data) {
                var optionstring = "<option value='0' >全部</option>";
                $.each(data.data, function (i, item) {
                    optionstring += "<option value=\"" + item.TypeID + "\" >" + item.Name + "</option>";
                });
                $("#ChchildProductTypeID").html(optionstring);
                form.render('select'); //这个很重要
            });
        });
        form.on('submit(sub)', function (data) {
            var imgurl="";
            $('#img-error img').each(function(){
                imgurl+=$(this).attr("src")+",";
                console.log(imgurl);
            })
            $('#imgsrc').val(imgurl);
            data.field[$("#imgsrc").attr("name")] = imgurl;
            data.field["Contenst"] = UE.getEditor('editor').getContent();
            //data.field[$("#LAY_demo_editor").attr("name")] = layedit.getContent(editIndex);

            $.post('/AdminInfo/AdminProduct/AddProductInfo', data.field, function (r) {
                if (r.status == 200) {
                    layer.msg(r.message);
                } else {
                    layer.msg(r.message);
                }
            });
            return false;
        });

    });
</script>

